package com.oa.framework.org.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.oa.framework.org.dao.PositionDao;
import com.oa.framework.org.domain.Position;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author cuichao
 */
@Service
public class PositionServiceImpl implements PositionService {

    @Autowired
    private PositionDao positionDao;


    @Override
    public List<Position> loadPositions() {
        QueryWrapper<Position> query = new QueryWrapper<>();
        query.orderByDesc("pos_level");
        List<Position> positions = positionDao.selectList(query);
        return positions;
    }

    @Override
    public List<Position> loadEnablePositions() {
        QueryWrapper<Position> query = new QueryWrapper<>();
        query.eq("disable",0);
        query.orderByDesc("pos_level");
        List<Position> positions = positionDao.selectList(query);
        return positions;
    }


    @Override
    public Position getPosition(Long positionId) {
        return positionDao.selectById(positionId);
    }


    @Override
    public boolean addPosition(Position position) {
        final int createSuccessFlag = 1;
        int flag = positionDao.insert(position);
        if (createSuccessFlag != flag) {
            return false;
        }
        return true;
    }


    @Override
    public boolean updatePosition(Position position) {
        final int updateSuccessFlag = 1;
        int flag = positionDao.updateById(position);
        if (updateSuccessFlag != flag) {
            return false;
        }
        return true;
    }


    @Override
    public boolean disablePosition(Long positionId) {
        final int disableSuccessFlag = 1;
        int flag = positionDao.disablePosition(positionId);
        if (disableSuccessFlag != flag) {
            return false;
        }
        return true;
    }
}

